package array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class L228 {
    public List<String> summaryRanges(int[] nums) {
        List<String> strings = new ArrayList<>();
        if (nums == null || nums.length == 0) return strings;
        int start = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i - 1] != nums[i]-1) {
                if (start==i-1){
                    strings.add(String.valueOf(nums[start]));
                }else
                    strings.add(nums[start] + "->" + nums[i-1]);
                start = i;
            }
        }
        if (start == nums.length-1) {
            strings.add(String.valueOf(nums[start]));
        }else
            strings.add(nums[start] + "->" + nums[nums.length-1]);
        return strings;

    }

    public static void main(String[] args) {
        L228 l228 = new L228();
        System.out.println(l228.summaryRanges(new int[]{0,1,2,4,5,7}));
    }
}
